<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<META content="text/html;charset=UTF-8" http-equiv="content-type">
<META name="GENERATOR" content="MSHTML 9.00.8112.16496"></HEAD>
<style type="text/css">
	.t1{width:100%}
	.t2{width:100%}
	.t1 td{border:1px solid black;}	
	.t2 td{border:1px solid black;}	

</style>

<script src="jquery1.3.2.js"></script>
<script src="socket.js"></script>
<script src="math.js"></script>
<script>
	$(function() {

		var iosocket = io.connect();

		iosocket.on('connect', function() {
			$('#incomingChatMessages').append($('<li>Connected</li>'));

			iosocket.on('message',
					function(message) {
						$('#incomingChatMessages').append(
								$('<li></li>').text(message));
					});
			iosocket.on('disconnect', function() {
				$('#incomingChatMessages').append('<li>Disconnected</li>');
			});

			iosocket.on('bet', function(message) {
				//$('#incomingChatMessages').append($('<li>' +message.luck+ '</li>'));
				/* if (message.name == -1) {
					alert(message.msg);
					return;
				} */
				// $('<tr><td>'+message.name+'</td><td>'+message.time+'</td><td>'+message.bill+'</td><td>'+message.luck+'</td><td>'+message.condition+'</td><td>'+message.betSize+'</td><td>'+message.beiLv+'</td><td>'+message.profit+'</td></tr>').prependTo('#tt'); 
				if ($("#tt").find("tr").length > 100) {
					$("#tt tr:last").remove(); //这个是删除
				}
				$('#tt').prepend(
						'<tr><td style="width:10%">' + message.name
								+ '</td><td style="width:15%">' + message.time
								+ '</td><td style="width:10%">' + message.bill
								+ '</td><td style="width:10%">' + message.luck
								+ '</td><td style="width:10%">'
								+ message.condition
								+ '</td><td style="width:10%">'
								+ message.betSize
								+ '</td><td style="width:10%">' + message.beiLv
								+ '</td><td style="width:10%">'
								+ message.profit + '</td></tr>');
			});

			iosocket.on('initBetList', function(objs) {
				$.each(objs, function(n, message) {
					if ($("#tt").find("tr").length > 100) {
						$("#tt tr:last").remove(); //这个是删除
					}
					$('#tt').prepend(
							'<tr><td style="width:10%">' + message.name
									+ '</td><td style="width:15%">'
									+ message.time
									+ '</td><td style="width:10%">'
									+ message.bill
									+ '</td><td style="width:10%">'
									+ message.luck
									+ '</td><td style="width:10%">'
									+ message.condition
									+ '</td><td style="width:10%">'
									+ message.betSize
									+ '</td><td style="width:10%">'
									+ message.beiLv
									+ '</td><td style="width:10%">'
									+ message.profit + '</td></tr>');

				});
				// $('<tr><td>'+message.name+'</td><td>'+message.time+'</td><td>'+message.bill+'</td><td>'+message.luck+'</td><td>'+message.condition+'</td><td>'+message.betSize+'</td><td>'+message.beiLv+'</td><td>'+message.profit+'</td></tr>').prependTo('#tt'); 
			});

			iosocket.on('error', function(message) {
				var errorMsg = message.msg;
				alert(errorMsg);
				return;
			});
		});

		var isPrintableKey = function(k) {
			return (k >= 48 && k <= 57) || // 数字
			(k >= 96 && k <= 105) || // 小键盘数字
			// 其他符号键
			(k === 110)
		};

		$('#outgoingChatMessage').keypress(function(event) {
			if (event.which == 13) {
				event.preventDefault();
				iosocket.send($('#outgoingChatMessage').val());
				// $('#incomingChatMessages').append($('<li></li>').text($('#outgoingChatMessage').val()));
				//  $('#outgoingChatMessage').val('');
			}
		});

		$('#betBig').click(function() {

			var data = {
				beiLv : $('#beiLv').val(),
				betSize : $('#betSize').val(),
				type : 1
			};
			iosocket.emit("bet", data);
		});

		$('#betSmall').click(function() {

			var data = {
				beiLv : $('#beiLv').val(),
				betSize : $('#betSize').val(),
				type : 0
			};
			iosocket.emit("bet", data);
		});

		$('#winPercent').keyup(function(event) {
			if (!isPrintableKey(event.which))
				return;
			//alert(event.which);
			//  if((event.which >= 96 && event.which <= 105) || event.which == 110) {
			//    event.preventDefault();

			$('#beiLv').val('');
			$('#beiLv').val(numDiv(99, $(this).val(), 2));
			//if($(this).val().split(".").length > 2)
			//$('#incomingChatMessages').append($('<li></li>').text($('#outgoingChatMessage').val()));
			//$('#outgoingChatMessage').val('');
			// }
		});

		$('#beiLv').keyup(function(event) {
			if (!isPrintableKey(event.which))
				return;
			$('#winPercent').val('');
			$('#winPercent').val(numDiv(99, $(this).val(), 2));

		});

		$('#betSize').keyup(function(event) {
			if (!isPrintableKey(event.which))
				return;
			$('#profit').val('');
			var a = $('#beiLv').val() - 1;
			// $('#profit').val(numMutil(a, $(this).val(), 2));
			var a = numSub($('#beiLv').val(), 1);
			var b = numMulti(a, $(this).val());
			$('#profit').val(b);

		});
	});

	function timerStart(func, delay) {
		var TimerID = window.setInterval(function() {
			if (!func()) {
				window.clearInterval(TimerID);
			}
			;
		}, delay);
	}
</script>
</head>
<body>
<ul id="incomingChatMessages"></ul>
<br />
test : <input type="text" id="outgoingChatMessage" />

win percent <input type="text" id="winPercent" />%
bei lv <input type="text" id="beiLv" />
bet size <input type="text" id="betSize" />
profit <input type="text" id="profit" />
<input type="button" id="betBig" value="bet big" />
<input type="button" id="betSmall" value="bet small" />
<table class="t1"><tr><td style="width:10%">名称</td><td style="width:15%">时间</td><td style="width:10%">投注单号</td><td style="width:10%">幸运数</td><td style="width:10%">条件</td><td style="width:10%">投注</td><td style="width:10%">倍率</td><td style="width:10%">盈利</td></tr></table>

<table class="t2" id="tt"></table>


</body>
</html>